package com.etocrm.saas.lib.base.log.requestlog.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.ContentType;

import javax.servlet.ServletRequest;
import java.util.Objects;

/**
 * Created by Xs on 2022/12/14.
 */
public class RequestUtil {

    /**
     * * 请求类型是否是Json请求
     *
     * @param request request
     * @return true = application/json; false = 其他
     */
    public static boolean isJsonRequest(ServletRequest request) {
        String contentType = request.getContentType();
        if (StrUtil.isBlank(request.getContentType())) {
            return false;
        }

        contentType = contentType.toLowerCase().split(";")[0].trim();
        return Objects.equals(contentType, ContentType.JSON.getValue());
    }
}
